#pragma once

/************************************************************************/
/* 管理消息队列
1,管理从客户端发送过来的消息(websocket, http, tcp消息)
2,返回给客户端的的消息(websocket, http, tcp消息)
3,把1的消息分发给后端的处理线程
*/
/************************************************************************/


#include "comm_def.h"

#include "ProcManager.h"
#include "ThirdPartyHeads.h"

#include "concurrentqueue.h"

class MessageQueueManager
{
public:
	static void SAsyncRecvDataCallback(uS::Async* handle);
public:
	MessageQueueManager();
	~MessageQueueManager();
	void InitMessageQueueManager(std::shared_ptr<ProcManager> proc);

	void AddWebRequestMessage(SessionType sessionid, const char* msg, size_t len);
	void AddWebResponseMessage(SessionType sessionid, const char* msg, size_t len, ResponseType broadType);
	std::shared_ptr<SessionResponseMessage> GetWebMessageResp();
	void AddSocketMessage(SessionType sessionid, char* msg, size_t len);

	void DispathMessageThreadFunc();
	void MemAsyncRecvDataCallback();

private:
	std::shared_ptr<std::thread> _dispathcThread;

	moodycamel::ConcurrentQueue<std::shared_ptr<SessionRequestMessage>> _sockRecvQueue;
	moodycamel::ConcurrentQueue<std::shared_ptr<SessionResponseMessage>> _sockSendQueue;
	moodycamel::ConcurrentQueue<std::shared_ptr<SessionRequestMessage>> _webRecvQueue;
	moodycamel::ConcurrentQueue<std::shared_ptr<SessionResponseMessage>> _webSendQueue;

	std::shared_ptr<ProcManager> _procPt;
	std::shared_ptr<uS::Async> _asyncRecvClientData;
	bool _run = false;
};

